package com.winsomely.leecode;

/**
 * 各位相加
 * 
 * @author liujiawei
 *
 */
public class AddDigits {

	public int addDigits(int num) {
		String s = String.valueOf(num);
		int h = -1;
		while (h > 9 || h < 0) {
			h = 0;
			for (int i = 0; i < s.length(); i++) {
				h += Integer.parseInt(s.charAt(i) + "");
			}
			s = String.valueOf(h);
		}
		return h;
	}

	// 12345
	public static void main(String[] args) {
		AddDigits t = new AddDigits();
		System.out.println(t.addDigits(707123464));
	}

}
